<template>
  <div class="container">
    <div class="loginBox">
      <span class="title">Sign In</span>
      <div class="logo">
        <span>daily-new</span>
      </div>
      <!-- 登录表单 -->
      <van-form @submit="onSubmit">
        <van-field
          v-model="user.mobile"
          type="number"
          name="mobile"
          placeholder="请输入手机号"
          :rules="[{ required: true, message: '请填写手机号' }]"
        />
        <van-field
          v-model="user.code"
          placeholder="请输入密码"
          name="code"
          type="password"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 30px 16px;">
          <van-button :loading="loadingState" :disabled="loadingState" round block type="info" native-type="submit" size="small" loading-text="登录中...">登录</van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import { userLoginAPI } from '@/api/index'
import { setToken } from '@/untils/token'
export default {
  data () {
    return {
      user: {
        mobile: '13664936875',
        code: '246810'
      },
      loadingState: false
    }
  },
  methods: {
    async onSubmit (value) {
      this.loadingState = true
      try {
        const res = await userLoginAPI(value)
        this.$toast.success('登录成功')
        setToken(res.data.data.token)
        this.$router.replace('/layout/home')
      } catch (error) {
        this.$toast.fail('用户名或密码错误')
      }
      this.loadingState = false
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  position: relative;
  width: 100%;
  height: 100%;
  background: url("../../assets/imgs/loginBg.jpg") no-repeat;
  background-size: 100% 100%;
  background-attachment: fixed;
  z-index: 1;
  color: #fff;
  .loginBox {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    // justify-content: center;
    align-items: center;
    z-index: 999;
    .title {
      margin-top: 30px;
      font-size: 20px;
      font-weight: normal;
    }
    .logo {
      width: 130px;
      height: 130px;
      border-radius: 30px;
      background-color: #fff;
      margin-top: 50px;
      span {
        display: block;
        background-color: #009CEF;
        width: 110px;
        height: 110px;
        border-radius: 50%;
        margin: 10px auto;
        line-height: 110px;
        text-align: center;
        font-size: 15px;
        font-weight: 800;
      }
    }
  }
}
.container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  background-color: rgba(17, 64, 110, .6);
}

.van-form {
  margin-top: 40px;
  width: 160px;
  height: 400px;
  .van-cell {
    background-color: transparent;
    color: #fff;
    font-size: 0.37rem;
  }
  .van-cell::after {
    border-bottom: none;
  }
  /deep/ .van-field__control {
    color: #fff;
  }
  /deep/ .van-field__body {
    border-bottom: 1px solid #eee;
    padding: 10px 0;
  }
  /deep/ .van-button--small {
    height: 0.85rem;
    font-size: 0.32rem;
  }
}

</style>
